/**
 * 智慧社区管理系统 - 移动端物业管理API接口
 * @author Wu.Liang
 * @date 2025-07-01
 * @description 移动端工程位于smart-community-app文件夹，严格遵循架构总览中的项目结构规范
 */

import request from './request'

// 物业费相关API（App端专用）
export const propertyFeeApi = {
  // 获取物业费列表
  getPropertyFeeList: (params) => {
    return request.get('/api/property/property-fees/list', { params })
  },

  // 获取当前用户的物业费账单（App端专用）
  getMyPropertyFees: (params) => {
    return request.get('/api/property/property-fees/mobile/my-fees', { params })
  },

  // 获取费用详情（App端专用）
  getFeeDetail: (id) => {
    return request.get(`/api/property/property-fees/mobile/detail/${id}`)
  },

  // 获取缴费记录
  getPaymentRecords: (feeId) => {
    return request.get('/api/property/property-fees/mobile/payment-records', { feeId })
  }
}

// 水电费管理API
export const utilityFeeApi = {
  // 分页查询水电费账单
  getUtilityFeeList: (params) => {
    return request.get('/api/property/utility-fees', { params })
  },

  // 获取水电费详情
  getUtilityFeeDetail: (billId) => {
    return request.get(`/api/property/utility-fees/${billId}`)
  },

  // 提交表读数
  submitMeterReading: (data) => {
    return request.post('/api/property/utility-fees/meter-reading', data)
  },

  // 批量提交表读数
  batchSubmitMeterReading: (data) => {
    return request.post('/api/property/utility-fees/batch-meter-reading', data)
  },

  // 查询用户未缴费水电费账单
  getUserUnpaidUtilityFees: (userId, feeType) => {
    const params = feeType ? { feeType } : {}
    return request.get(`/api/property/utility-fees/user/${userId}/unpaid`, { params })
  },

  // 水电费缴费
  payUtilityFee: (billId, data) => {
    return request.post(`/api/property/utility-fees/${billId}/pay`, null, {
      params: {
        paymentAmount: data.paymentAmount || data.amount,
        paymentMethod: data.paymentMethod
      }
    })
  },

  // 获取水电费统计信息
  getUtilityFeeStatistics: (params) => {
    return request.get('/api/property/utility-fees/statistics', { params })
  },

  // 获取社区列表
  getCommunityList: () => {
    return request.get('/api/region/communities')
  },

  // 获取楼栋列表
  getBuildingList: (params) => {
    return request.get('/api/region/buildings', { params })
  },

  // 获取房户列表
  getHouseholdList: (params) => {
    return request.get('/api/region/households', { params })
  },

  // 获取表读数历史记录
  getMeterReadingHistory: (params) => {
    return request.get('/api/property/utility-fees/meter-reading/history', { params })
  },

  // 获取上次表读数
  getLastMeterReading: (params) => {
    return request.get('/api/property/utility-fees/meter-reading/last', { params })
  }
}

// 物业公司管理API
export const propertyCompanyApi = {
  // 物业公司注册
  registerPropertyCompany: (data) => {
    return request.post('/api/property/companies/register', data)
  },

  // 获取物业公司列表
  getPropertyCompanyList: (params) => {
    return request.get('/api/property/companies', { params })
  },

  // 获取物业公司详情
  getPropertyCompanyDetail: (id) => {
    return request.get(`/api/property/companies/${id}`)
  }
}

// 燃气费管理API
export const gasFeeApi = {
  // 分页查询燃气费账单
  getGasFeeList: (params) => {
    return request.get('/api/property/gas-fees', { params })
  },

  // 获取燃气费详情
  getGasFeeDetail: (billId) => {
    return request.get(`/api/property/gas-fees/${billId}`)
  },

  // 提交燃气表读数
  submitGasMeterReading: (data) => {
    return request.post('/api/property/gas-fees/meter-reading', data)
  },

  // 查询用户未缴费燃气费账单
  getUserUnpaidGasFees: (userId) => {
    return request.get(`/api/property/gas-fees/user/${userId}/unpaid`)
  },

  // 燃气费缴费
  payGasFee: (billId, data) => {
    return request.post(`/api/property/gas-fees/${billId}/pay`, null, {
      params: {
        paymentAmount: data.paymentAmount || data.amount,
        paymentMethod: data.paymentMethod
      }
    })
  },

  // 获取燃气费统计信息
  getGasFeeStatistics: (params) => {
    return request.get('/api/property/gas-fees/statistics', { params })
  }
}

// 卫生费管理API
export const sanitationFeeApi = {
  // 分页查询卫生费账单
  getSanitationFeeList: (params) => {
    return request.get('/api/property/sanitation-fees', { params })
  },

  // 获取卫生费详情
  getSanitationFeeDetail: (billId) => {
    return request.get(`/api/property/sanitation-fees/${billId}`)
  },

  // 查询用户未缴费卫生费账单
  getUserUnpaidSanitationFees: (userId) => {
    return request.get(`/api/property/sanitation-fees/user/${userId}/unpaid`)
  },

  // 卫生费缴费
  paySanitationFee: (billId, data) => {
    return request.post(`/api/property/sanitation-fees/${billId}/pay`, null, {
      params: {
        paymentAmount: data.paymentAmount || data.amount,
        paymentMethod: data.paymentMethod
      }
    })
  },

  // 获取卫生费统计信息
  getSanitationFeeStatistics: (params) => {
    return request.get('/api/property/sanitation-fees/statistics', { params })
  }
}

// 在线支付API
export const paymentApi = {
  // 创建支付订单
  createPayment: (data) => {
    return request.post('/api/payment/create', data)
  },

  // 获取费用详情
  getFeeDetail: (feeId) => {
    return request.get(`/api/property/fees/${feeId}/detail`)
  },

  // 获取优惠券列表
  getCouponList: (params) => {
    return request.get('/api/property/coupons', { params })
  },

  // 查询支付状态
  getPaymentStatus: (orderNo) => {
    return request.get(`/api/payment/${orderNo}/status`)
  },

  // 分页查询支付记录
  getPaymentList: (params) => {
    return request.post('/api/payment/page', params)
  },

  // 获取支付详情
  getPaymentDetail: (id) => {
    return request.get(`/api/payment/${id}`)
  },

  // 申请退款
  applyRefund: (id, data) => {
    return request.post(`/api/payment/${id}/refund`, data)
  },

  // 取消支付订单
  cancelPayment: (id, reason) => {
    return request.put(`/api/payment/${id}/cancel`, { reason })
  },

  // 重新支付
  repayPayment: (id, paymentMethod) => {
    return request.post(`/api/payment/${id}/repay`, { paymentMethod })
  },

  // 获取支付统计概览
  getPaymentStatistics: (params) => {
    return request.get('/api/payment/statistics', { params })
  }
}

// 数据权限API
export const dataScopeApi = {
  // 获取当前用户数据权限信息
  getDataScopeInfo: () => {
    return request.get('/api/property/data-scope/current-user')
  },

  // 检查用户是否有指定社区权限
  checkCommunityPermission: (communityId) => {
    return request.get(`/api/property/data-scope/community/${communityId}/check`)
  },

  // 获取用户可访问的社区列表
  getUserCommunities: () => {
    return request.get('/api/property/data-scope/user-communities')
  },

  // 刷新用户权限缓存
  refreshUserPermissionCache: () => {
    return request.post('/api/property/data-scope/refresh-cache')
  }
}

// 通用API
export const commonApi = {
  // 获取社区列表
  getCommunityList: () => {
    return request.get('/api/region/communities')
  },

  // 获取楼栋列表
  getBuildingList: (params) => {
    return request.get('/api/region/buildings', { params })
  },

  // 获取房户列表
  getHouseholdList: (params) => {
    return request.get('/api/region/households', { params })
  },

  // 获取用户信息
  getUserInfo: () => {
    return request.get('/api/user/info')
  },

  // 上传文件
  uploadFile: (filePath) => {
    return request.uploadFile('/api/common/upload', filePath)
  }
} 